package com.liuyfly.leetcode.study;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/**
 * @author liuyangfang at 2022-09-28 17:57
 */
@Slf4j
public class ArrayPairSum {
    public static int arrayPairSum(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        Arrays.sort(nums);
        int result = 0;
        for (int i = 0; i < nums.length; i=i+2) {
            result += nums[i];
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = { 1, 4, 2, 3 };
        int result = arrayPairSum(nums);
        log.info("result:{}", result);
    }
}
